package com.example.springcloud;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

/**
 * 认证配置
 *
 * @author csp 2023-02-14
 */
@Configuration
public class WebSecurityConfig{

    @Bean
    UserDetailsService users() {
        UserDetails user = User.builder()
                .username("admin")
                .password("$2a$10$nAfLNnJLEKIuv60y5/noRuc3IQv6fEKlf0gHJ6.UD1.D7kwfFIus6")
                .roles("USER")
                .build();
        return new InMemoryUserDetailsManager(user);
    }


    @Bean
    PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

}